<template>
    <el-container class="container">
      <el-header class="header">
        <el-row>
          <el-col :span="8">
            <img src="../../assets/images/logo.png" alt>
          </el-col>
          <el-col :span="8">
            <h1>电商后台管理系统</h1>
          </el-col>
          <el-col :span="8" class="out">
            欢迎上海前端33期二楞头会员
            <a href="#" @click.prevent="logout">退出</a>
          </el-col>
        </el-row>
      </el-header>
      <el-container>
        <el-aside class="aside" width="200px">
          <el-menu
            :router = 'true'
            default-active="2"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
          >
            <el-submenu index="1">
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>用户管理</span>
              </template>
              <el-menu-item index='/users'>
                用户列表
              </el-menu-item>
            </el-submenu>
            <el-submenu index="2">
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>权限管理</span>
              </template>
              <el-menu-item index='/roles'>
                角色列表
              </el-menu-item>
              <el-menu-item index='/rights'>
                权限列表
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main class="main">
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
</template>

<script>
export default {
  methods: {
    logout () {
      this.$confirm('此操作将退出当前用户, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          // 1. 工作中有接口退出，现在删除token
          localStorage.removeItem('token')
          this.$router.push('login')
          this.$message({
            type: 'success',
            message: '退出成功!',
            durantion: 800
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消退出'
          })
        })
    },
    handleOpen (key, keyPath) {
      console.log(key, keyPath)
    },
    handleClose (key, keyPath) {
      console.log(key, keyPath)
    }
  }
}
</script>

<style lang="less">
* {
  padding: 0;
  margin: 0;
}
html,
body,
#app {
  height: 100%;
}
.container {
  height: 100%;
  min-width: 870px;
}

/* 头部 */
.header {
  height: 60px;
  background: #b3c1cd;
  padding: 0;
  h1 {
    color: #fff;
    font-size: 28px;
    text-align: center;
    line-height: 60px;
  }
  .out {
    text-align: center;
    line-height: 60px;
    padding-right: 40px;
    a {
      color: #daa521;
    }
  }
}
/* aside */
.aside {
  background: #545c64;
}

/* main */
.main {
  background: #eaeef1;
}
</style>
